<?php

class DisplayController extends Controller
{
    public $layout = '//layouts/topColumn';

    public $menuList;

    public $menuitemName;

	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
				'minLength'=>4,
				'maxLength'=>4,
                'testLimit'=>1,
            ),
		);
    }


	public function actionView($mid,$sid)
    {
        $this->render('index',array(
            'model'=>Submenu::model()->findByPk($sid),
            'modelMenuitem'=>Menuitem::model()->findByPk($mid),
        ));
	}

    public function actionNews($id)
    {

        $session = Yii::app()->session;
        if(!isset($session['newsReader'.$id]))
        {
            $session['newsReader'.$id] = 'view';
            $newsModel=News::model()->findByPk($id);
            $viewNum=$newsModel->views;
            $viewNum++;
            News::model()->updateByPk($id,
                array('views'=>$viewNum)
            );
        }
        $this->render('news',array(
            'model'=>News::model()->findByPk($id),
        ));
    }

    public function actionCourseList()
    {
        $dataProvider=new CActiveDataProvider('Course',array(
            'criteria'=>array(
            'condition'=>'status = '.Course::STATUS_ACTIVE,
            'order'=>'create_date DESC',
        )));
		$this->render('courseList',array(
			'dataProvider'=>$dataProvider,
		));
    }

    public function actionTeachingList()
    {
        $dataProvider=new CActiveDataProvider('Teaching',array(
            'criteria'=>array(
            'condition'=>'status = '.Teaching::STATUS_ACTIVE,
            'order'=>'create_date DESC',
        )));
		$this->render('teachingList',array(
			'dataProvider'=>$dataProvider,
		));
    }

    public function actionAnnouncement()
    {

	    $this->render('announcement',array(
			'dataProvider'=>News::getNewsByNewsType(News::TYPE_ANNOUNCEMENT),
		));
    }

    public function actionCenterNews()
    {
        $this->render('centernews',array(
			'dataProvider'=>News::getNewsByNewsType(News::TYPE_GENERAL),
		));
    }

    public function actionImageContentNews()
    {
        $this->render('imagecontentnews',array(
            'model'=>News::getNewsModelByNewsType(News::TYPE_IMAGECONTENT),
        ));
    }

    public function actionLabList()
    {
         $dataProvider=new CActiveDataProvider('Lab',array(
            'criteria'=>array(
            'order'=>'create_date DESC',
        )));
		$this->render('lablist',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionTeach()
    {
        $dataProvider=new CActiveDataProvider('Teaching',array(
            'criteria'=>array(
            'condition'=>'status = '.Teaching::TYPE_TEACH,
            'order'=>'create_date DESC',
        ),
        'pagination'=>array(
                'pageSize'=>yii::app()->params['pageSize'],
            ),
        ));
		$this->render('teach',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionPlatformResources()
    {
        $dataProvider=new CActiveDataProvider('Teaching',array(
            'criteria'=>array(
            'condition'=>'status = '.Teaching::TYPE_PLATFORM." and active = ".Teaching::STATUS_ACTIVE,
            'order'=>'create_date DESC',
            ),
                 'pagination'=>array(
                'pageSize'=>yii::app()->params['pageSize'],
            ),
        ));
		$this->render('platformresources',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionSchoolEnterprise()
    {
        $dataProvider=new CActiveDataProvider('Achievement',array(
            'criteria'=>array(
            'condition'=>'type_id = 1',
        ),
             'pagination'=>array(
                'pageSize'=>yii::app()->params['pageSize'],
            ),

        ));
		$this->render('schoolenterprise',array(
            'dataProvider'=>$dataProvider,
		));
    }
 
    public function actionScientificAchievement()
    {
        $dataProvider=new CActiveDataProvider('Achievement',array(
            'criteria'=>array(
            'condition'=>'type_id = 2',
        ),
        'pagination'=>array(
            'pageSize'=>yii::app()->params['pageSize'],
        ),
    ));
        $this->render('scientificachievement',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionTeachingAchievement()
    {
        $dataProvider=new CActiveDataProvider('Achievement',array(
            'criteria'=>array(
            'condition'=>'type_id = 3',
        )));
		$this->render('teachingachievement',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionInstrument()
    {
        $dataProvider=new CActiveDataProvider('Instrument',array(
            'criteria'=>array(
            'condition'=>'status = 1',
        )));
		$this->render('instrument',array(
            'dataProvider'=>$dataProvider,
		));
    }

    public function actionResultsShow()
    {
        $this->render('resultsshow');
    }

    public function actionContactUs()
    {
        $this->render('contactus');
    }

    public function actionRelatedLink()
    {
        if(isset($_GET['type']))
        {
            if($_GET['type'] == '校内链接.html')
            {
                $lModel = Relatedlink::model()->findAll("type = ".Relatedlink::TYPE_SCHOOL_IN);
                $type = 1;
            }
            elseif($_GET['type'] == '校外链接.html')
            {
                $lModel = Relatedlink::model()->findAll("type = ".Relatedlink::TYPE_SCHOOL_OUT);
                $type = 2;
            }
            else
            {
                $lModel = Relatedlink::model()->findAll();
                $type = 3;
            }
        }
        else
        {
                $lModelIN = Relatedlink::model()->findAll("type = ".Relatedlink::TYPE_SCHOOL_IN);
                $lModelOUT = Relatedlink::model()->findAll("type = ".Relatedlink::TYPE_SCHOOL_OUT);
                $type = 3;
        }
        $this->render('relatedlink',
            array(
                'model'=>$lModel,
                'type'=>$type,
                'lModelIN'=>$lModelIN,
                'lModelOUT'=>$lModelOUT,
        ));
    }

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}
